<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var a = 0;

    function* execFunc () {
        let width;
        console.log(width)
        width = yield 1;
        console.log(width)
        width = yield 1;
        console.log(width)
        width = yield 1;
        console.log(width)
        width = yield 1;
        console.log(width)
    }

    const exec = execFunc ()
    exec.next();

    function execDirector () {
        if (a === 2000) {
            exec.next(a)
        } else if (a === 1000) {
            exec.next(a)
        } else if (a === 800) {
            exec.next(a)
        }  else if (a === 0) {
            exec.next(a)
        }
        // a = 0;
    }

    function run (width) {
        if (a <= width) a = width
        execDirector ()
        a += 1;
    }

    run (0)
    run (10)
    run (20)
    run (800)
    run (850)
    run (900)
    run (1000)
    run (1110)
    run (1199)
    run (2000)

</script>
</body>
</html>